import React, { Component } from 'react'
import { connect } from 'react-redux'

export class Home extends Component {
    render() {
        const { count, add, del } = this.props
        return (
            <div>
                <button onClick = { del }>--</button>
                    { count }
                <button onClick = { add }>++</button>
            </div>
        )
    }
}

const mapStateToProps = (state) => {
    const { count } = state
    return {
        count
    }
}

const mapDispatchToProps = (dispatch) => {
    return {
        add() {
            dispatch({ type: "TAKE_ADD_COUNT" })
        },
        del() {
            dispatch({ type: "TAKE_DEL_COUNT" })
        }
    }
}

export default connect(mapStateToProps, mapDispatchToProps)(Home)
